//
//  ZYCProtalCanlendarBottomView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/2.
//

#import "ZYCProtalCanlendarBottomView.h"


@interface ZYCProtalCanlendarBottomView ()

@property (nonatomic, strong) UIButton *readButton;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
@end
@implementation ZYCProtalCanlendarBottomView

- (void)setReadFlag:(NSInteger)readFlag{
    _readFlag = readFlag;
    if (readFlag == 0) {//未读
        [self addGradientLayer];
        [self.readButton setTitleColor:HEX_RGB(kTitleWhiteColor) forState:UIControlStateNormal];
    }else{
        self.readButton.enabled = NO;
        [self.readButton setTitleColor:HEX_RGB(@"#B3B2B2") forState:UIControlStateNormal];
        self.readButton.backgroundColor = HEX_RGB(@"#D5D5D5");
    }
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#F9F9F9");
        [self addSubview:self.readButton];
        [self.readButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(240, 40));
        }];
    }
    return self;
}

- (void)addGradientLayer{
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.startPoint = CGPointMake(0, 0);
    gl.endPoint = CGPointMake(1, 0);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:245/255.0 green:235/255.0 blue:167/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:0/255.0 green:144/255.0 blue:67/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0),@(0.4f)];
    gl.frame = _readButton.bounds;
    gl.cornerRadius = 20;
    [_readButton.layer insertSublayer:gl atIndex:0];
}

- (UIButton *)readButton {
    if (!_readButton) {
        _readButton = [[UIButton alloc] init];
        _readButton.frame = CGRectMake(0, 0, 240, 40);
        [_readButton setTitle:@"读" forState:UIControlStateNormal];
        _readButton.backgroundColor = HEX_RGB(@"#39A85B");
        _readButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 18.0f);
        [_readButton addTarget:self action:@selector(clickReadAction:) forControlEvents:UIControlEventTouchUpInside];
        _readButton.layer.cornerRadius = 20.f;
        _readButton.layer.masksToBounds = YES;
    }
    return _readButton;
}

- (void)clickReadAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(protalCanlendarBottomViewDidRead)]) {
        [self.delegate protalCanlendarBottomViewDidRead];
    }
}
@end
